<h1><%= @eapp.title %></h1>

<h2>Update data</h2>
<p>Scan the log files and update the data. You may select a load test with which to associate the most recent requests.</p>
<%= form_tag url={:action => :run, :id => @eapp.id} %>
<p><label>Load test<br /><%= select("eload", "id", @eapp.eloads.collect{|eload| [eload.title, eload.id]}, {:include_blank => true})%></label></p>
<p><%= submit_tag "Update data" %></p>
</form>

<h2>Date range</h2>
<p>Specify the date range you would like to show up in the analysis.</p>
<%= form_tag url={:action => :date_range, :id => @eapp.id} %>
<p><%= date_select("eapp", "start_on", :include_blank => true) %> to <%= date_select("eapp", "end_on", :include_blank => true) %> <%= submit_tag "Select date range" %></p>
</form>

<h2>Load tests</h2>
<p>Select the load test you would like to show up in the analysis.</p>
<%= form_tag url={:action => :load_update, :id => @eapp.id} %>
<% 
eload = Eload.find(:first, :conditions => ["eapp_id=? and active=1",@eapp.id]) 
select = 0
select = eload.id if eload
%>
<p><%= select("eload", "id", @eapp.eloads.collect{|eload| [eload.title, eload.id]}, {:selected => select, :include_blank => true})%> 
<%= submit_tag "Select load test" %></p>
</form>
<%= form_tag url={:action => :load_new, :id => @eapp.id} %>
<p><label>Title<br /><%= text_field "eload", "title" %></label> <%= submit_tag "New load test" %></p>
</form>

<h2>Profile</h2>
<p>Get a line by line time profile of a specific URL.</p>
<%= form_tag url={:action => :profile, :id => @eapp.id} %>
<p><label>http://0.0.0.0:3000/<%= text_field "profile", "get" %></label> <%= submit_tag "Profile" %></p>
</form>

<table>
<tr>
<th></th>
<th colspan="<%= @calculations.length %>">Total time</th>
<th colspan="<%= @calculations.length %>">Rendering time</th>
<th colspan="<%= @calculations.length %>">DB time</th>
<th colspan="2">Requests</th>
</tr>
<tr>
<th>Name</th>
<% for column in @columns %>
<% for calculation in @calculations %>
<% if column==@sort_column and calculation==@sort_calculation %> 
<th><%= link_to calculation, {:sort_column => column, :sort_calculation => calculation} %></th>
<% else %>
<td><%= link_to calculation, {:sort_column => column, :sort_calculation => calculation} %></td>
<% end %>
<% end %>
<% end %>
<% if "count"==@sort_calculation %>
<th><%= link_to "count", {:sort_column => "id", :sort_calculation => "count"} %></th>
<th><%= link_to "percentage", {:sort_column => "id", :sort_calculation => "count"} %></th>
<% else %>
<td><%= link_to "count", {:sort_column => "id", :sort_calculation => "count"} %></td>
<td><%= link_to "percentage", {:sort_column => "id", :sort_calculation => "count"} %></td>
<% end %>
</tr>
<% for erequest in @erequests %>
<% controller = erequest[:econtroller].econtroller.title.titlecase %>
<tr>
<td><%= controller %></td>
<% for column in @columns %>
<% for calculation in @calculations %>
<td><%= erequest[:econtroller][column+"_"+calculation] %></td>
<% end %>
<% end %>
<% count_total = erequest[:econtroller]["count"] %>
<td><%= erequest[:econtroller]["count"] %></td>
<td></td>
</tr>
<% for erequest in erequest[:eactions] %>
<tr>
<td><%= link_to controller+"#"+erequest.eaction.title, {:action => :action, :id => erequest.eaction.id} %></td>
<% for column in @columns %>
<% for calculation in @calculations %>
<td><%= erequest[column+"_"+calculation] %></td>
<% end %>
<% end %>
<td><%= erequest["count"] %></td>
<td><%= sparkline_tag [erequest["count"].to_f/count_total*100], :type => 'pie' %></td>
</tr>
<% end %>
<% end %>
</table>
